/*
 * RegexpFilter.cc
 * Author: Michal Kolodziejski
 */

#include "RegexpFilter.h"

RegexpFilter::RegexpFilter() : NAME("RegexpFilter") {
}

RegexpFilter::~RegexpFilter() {
    filters.clear();
}


bool RegexpFilter::process(std::string &content){
    FiltersList::iterator it;
    for(it = filters.begin(); it != filters.end(); ++it){
        content = boost::regex_replace(content, *it, "", boost::match_default);
    }
    return true;
}


bool RegexpFilter::processConfig(std::string path){
    // clear old config data
    filters.clear();

    std::ifstream configFile(path.c_str());
    if(!configFile.is_open()){
        return false;
    }

    std::string line;
    while(std::getline(configFile, line)){
        if(line.size() == 0)
            continue;
        if(line.substr(0,1) == "#")
            continue;   /* comment, do nothing */

        boost::regex r(line);
        filters.push_back(r);
    }
    configFile.close();
    return true;
}
